#include "Assert.h"

#include "Test.h"

namespace {
	TEST(AssertEqualsInt) {
		ASSERT_EQUALS(3, 3);
	}

	TEST(AssertEqualsIntFailed) {
		try {
			assertEquals(3, 4, "", 0);
		}
		catch (AssertFailedException& actual) {
			AssertFailedException expected;
			expected.type = "AssertEquals";
			expected.expected = "3";
			expected.actual = "4";
			expected.file = "";
			expected.line = 0;
			ASSERT_EQUALS(expected, actual);
		}
	}

	TEST(AssertEqualsString) {
		ASSERT_EQUALS("hallo", "hallo");
	}

	TEST(AssertEqualsStringFailed) {
		try {
			assertEquals("hallo", "bye", "", 0);
		}
		catch (AssertFailedException& actual) {
			AssertFailedException expected;
			expected.type = "AssertEquals";
			expected.expected = "hallo";
			expected.actual = "bye";
			expected.file = "";
			expected.line = 0;
			ASSERT_EQUALS(expected, actual);
		}
	}

	TEST(AssertEqualsLongString) {
		ASSERT_EQUALS("Hallo ich bin lang", "Hallo ich bin lang");
	}

	TEST(AssertNull) {
		ASSERT_NULL(NULL);
	}

	TEST(AssertNullFailed) {
		try {
			int i = 0;
			assertNull(&i, "", 0);
			throw 0;
		}
		catch (AssertFailedException& actual) {
			AssertFailedException expected;
			expected.type = "AssertNotNull";
			expected.expected = "not NULL";
			expected.actual = "NULL";
			expected.file = "";
			expected.line = 0;
			ASSERT_EQUALS(expected, actual);
		}
	}

	TEST(AssertEqualsVector) {
		vector<string> v1;
		vector<string> v2;

		v1.push_back("val1");
		v1.push_back("val2");

		v2.push_back("val1");
		v2.push_back("val2");

		ASSERT_EQUALS(v1, v2);
	}

	TEST(AssertEqualsVectorFailed) {
		try {
			vector<string> v1;
			vector<string> v2;

			v1.push_back("val1");
			v1.push_back("val2");

			v2.push_back("val1");

			assertEquals(v1, v2, "", 0);
		}
		catch (AssertFailedException& actual) {
			AssertFailedException expected;
			expected.type = "AssertEqualsSequence";
			expected.expected = "val1 val2";
			expected.actual = "val1";
			expected.file = "";
			expected.line = 0;
			ASSERT_EQUALS(expected, actual);
		}
	}
	
	TEST(AssertNotNull) {
		int i;
		int* pi = &i;
		assertNotNull(pi, __FILE__, __LINE__);
	}

	TEST(AssertNotNullFailed) {
		try {
			assertNotNull(NULL, "", 0);
		}
		catch (AssertFailedException& actual) {
			AssertFailedException expected;
			expected.type = "AssertNotNull";
			expected.expected = "not NULL";
			expected.actual = "NULL";
			expected.file = "";
			expected.line = 0;
			ASSERT_EQUALS(expected, actual);
		}
	}

	TEST(AssertTrue) {
		assertTrue(true, __FILE__, __LINE__);
	}

	TEST(AssertTrueFailed) {
		try {
			assertTrue(false, "", 0);
		}
		catch (AssertFailedException& actual) {
			AssertFailedException expected;
			expected.type = "AssertTrue";
			expected.expected = "true";
			expected.actual = "false";
			expected.file = "";
			expected.line = 0;
			ASSERT_EQUALS(expected, actual);
		}
	}

	TEST(AssertFalse) {
		assertFalse(false, __FILE__, __LINE__);
	}

	TEST(AssertFalseFailed) {
		try {
			assertFalse(true, "", 0);
		}
		catch (AssertFailedException& actual) {
			AssertFailedException expected;
			expected.type = "AssertFalse";
			expected.expected = "false";
			expected.actual = "true";
			expected.file = "";
			expected.line = 0;
			ASSERT_EQUALS(expected, actual);
		}
	}

	TEST(IntToString) {
		ASSERT_EQUALS((string)"6", intToString(6));
	}
}